package com.javasm.activitymgr.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.activitymgr.Activity;
import com.javasm.activitymgr.ActivityGoods;
import com.javasm.activitymgr.ActivityGoodsService;
import com.javasm.activitymgr.ActivityService;
import com.javasm.activitymgr.dao.ActivityDao;
import com.javasm.activitymgr.dao.ActivityGoodsDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityDao, Activity> implements ActivityService {
@Resource
    private ActivityGoodsDao afg;
@Resource
    private ActivityGoodsService ags;

    @Transactional
    @Override
    public boolean save(Activity entity) {
        super.save(entity);
        String id = entity.getId();
        List<ActivityGoods> aglist = entity.getAglist();
        for (ActivityGoods activityGoods : aglist) {
            activityGoods.setActivityId(id);
        }
        ags.saveBatch(aglist);
        return true;
    }

    @Override
    public List<ActivityGoods> listActivitiGoods(String id) {

        List<ActivityGoods> a = afg.listActivitiGoods(id);
        return a;
    }
}
